<template>
    <div>
        <c-header :p-title="'申请详情'">
            <div class="d-flex justify-content-end align-items-center">
                <button  class="btn btn-sm btn-danger m-r-sm" type="button" @click="exportFile">导出审核失败</button>
                <button type="button" class="btn btn-sm btn-info d-lg-block"  @click="$router.go(-1)"><i class="fa fa-mail-reply m-r-sm"></i>返回</button>
                <btn-refresh class='m-l-15' :p-data='init'></btn-refresh>
            </div>
        </c-header>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive"  v-if='list'>
                            <rich-table
                                    :p-data='list'
                            >
                                <div class="table-edit-group" slot="eidt" slot-scope="slotProps">
                                    <button v-if="slotProps.item.status=='1'" class="btn btn-sm btn-success" type="button" @click="editDetail('edit',slotProps.item)">编辑</button>
                                    <!--
                                    <button v-if="slotProps.item.status=='1'" class="btn btn-sm btn-danger m-l-sm" type="button" @click="editDetail('time',slotProps.item)">修改抵离时间</button>-->
                                </div>
                            </rich-table>
                            <div  v-show='!list.length' class="text-center m-b-sm">
                                暂无数据！
                            </div>
                        </div>
                        <hr/>
                        <footer class="panel-footer text-right">
                            <CPage :total="search.page_total"
                                   :current='search.page_current'
                                   :page-size='search.page_row'
                                   @on-change='pageCurrentChange'
                                   @on-page-size-change='pageRowChange'></CPage>
                        </footer>
                    </div>
                </div>
            </div>
        </div>
        <operate-save-inset ref="operate_save_inset" @on-change="initSubmit"></operate-save-inset>
    </div>
</template>
<script>
    import serWorkerWrite from '../../serves/api-worker-write'
    import richTable from '../customer/RichTable'
    import operateSaveInset from '../customer/saveInset'

    const __page_key = 'worker.write.verity.detail';
    let searchDef = {
        page_row:'',
        page_current:'',
        page_total:''
    };
    export default{
        components:{
            richTable,
            operateSaveInset,
        },
        data(){
            return{
                id:'',
                list:undefined,
                search:{},
            }
        },
        computed:{
        },
        beforeMount(){
            this.$set(this, 'id',this.pParams&&this.pParams.id||this.$route.params.id);
            this.searchReset();
        },
        mounted(){
            this.init();
        },
        methods:{
            searchReset(update,pageState){
                if(pageState){
                    this.$clientPage.def(this.search);
                    return false
                }
                const _p=this.$clientPage.getData(__page_key);
                if(_p){
                    this.$set(this,'search',_p);
                }else{
                    this.$set(this,'search',Object.assign({},searchDef));
                    this.$clientPage.def(this.search);
                }
                if(update){
                    this.init();
                }
            },
            searchPage(page){
                this.$clientPage.set(this.search,page);
            },
            searchChange(){
                this.$clientPage.def(this.search);
                this.init();
            },
            pageRowChange(num){
                if(num!= this.search.page_row){
                    this.$set(this.search,'page_row',num);
                    if(this.search.page_current == 1){
                        this.init();
                    }
                }
            },
            pageCurrentChange(current){
                if(current!= this.search.page_current){
                    this.$set(this.search,'page_current',current);
                    this.init();
                }
            },
            linkPageChange(name,params,query){
                this.$clientPage.setData(__page_key,Object.assign({},this.search));
                if(name){
                    this.$router.push({name:name,params:params,query:query})
                }
            },
            //------------------------------------------------------------------------
            async init(data){
                let res = await serWorkerWrite.detailVerity({
                    page:this.search.page_current,
                    size:this.search.page_row,
                    id:this.id,
                });
                if(res.code==1){
                    res.data.forEach((v,i)=>{
                       if(v.status!='-3'){
                           v._disabled = true;
                       }
                    });
                    this.list = res.data||[];
                    this.searchPage(res.addtion_data&&res.addtion_data.page_info);
                }else{
                    this.list = [];
                    this.searchReset(undefined,true);
                    this.$Message.error(res.message);
                }
                return true;
            },
            initSubmit(state){
                if(state){
                    this.init()
                }
            },
            editDetail(type,data){
                let modal_name = '';
                if(type=='edit'){
                    modal_name = 'operate_save_inset';
                    this.$refs[modal_name].handleOpen({
                        id:data.id,
                        _type:'edit',
                    });
                    return false;
                }else if(type=='time'){
                    modal_name = 'operate_inject'
                }
                this.$refs[modal_name].handleOpen({
                    id:data.id
                });
            },
            exportFile(){
                serWorkerWrite.exportNoVerityFile({
                    id:this.id,
                });
            }
        }
    }
</script>